<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\OrderPedestrian as OrderPedestrianModel;

/**
 * OrderPedestrian 出行人控制器
 * Class OrderPedestrian
 * @package app\home\controller
 */
class OrderPedestrian extends Base
{
    /**
     * [getIndex  获取出行人]
     * @return json
     * @author [C。]
     */
    public function getIndex()
    {
        $model = new OrderPedestrianModel();
        $user = $this->user;
        try{
            $list = $model->getAllData(['memid'=>$user['id'],'status'=>1],'id','id,idcard,name,tel');
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1, '获取成功',$list);
    }
    /**
     * [getAdd  添加修行设置]
     * @return json
     * @author [C。]
     */
    public function postAdd()
    {
        $param = input('param.');
        $model = new OrderPedestrianModel();
        $user = $this->user;
        try{
            if(!is_idcard($param['idcard']))
                return admin_json(-2,'身份证错误！');
            $person = $model->findOne(['memid'=>$user['id'],'idcard'=>$param['idcard'],'status'=>1]);
            if(!empty($person)){
                return admin_json(-3,'该身份证号已存在！');
            }
            $param['memid'] = $user['id'];
            $model->addData($param);
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '添加失败'.$e->getMessage());
        }
        return admin_json(1, '添加成功');
    }
    /**
     * [getEdit  修改修行设置]
     * @return json
     * @author [C。]
     */
    public function postEdit()
    {
        $param = input('param.');
        $model = new OrderPedestrianModel();
        try{
            if(!is_idcard($param['idcard']))
                return admin_json(-2,'身份证错误！');

            $model->editData($param);
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        return admin_json(1, '修改成功');
    }
    /**
     * [getDel  删除设置]
     * @return json
     * @author [C。]
     */
    public function getDel()
    {
        $param = input('param.');
        $model = new OrderPedestrianModel();
        try{
            $model->editData(['id'=>$param['id'],'status'=>2]);
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '删除失败'.$e->getMessage());
        }
        return admin_json(1, '删除成功');
    }
    /**
     * [getDel  删除设置]
     * @return json
     * @author [C。]
     */
    public function getOne()
    {
        $param = input('param.');
        $model = new OrderPedestrianModel();
        try{
            $pedestrian = $model->findData($param['id'],'id','id,idcard,name,tel');
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1, '获取成功',$pedestrian);
    }
}